/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.digitalization.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.digitalization.entity.UmsUserInfoEntity;
import org.springblade.modules.digitalization.service.IUmsUserInfoService;
import org.springblade.modules.digitalization.vo.UmsUserInfoVO;
import org.springblade.modules.digitalization.wrapper.UmsUserInfoWrapper;
import org.springblade.modules.system.service.IMenuService;
import org.springblade.modules.system.vo.MenuVO;
import org.springframework.core.io.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

/**
 * 人员基础模型-JAVA 控制器
 *
 * @author RS
 * @since 2022-10-18
 */
@RestController
@AllArgsConstructor
@RequestMapping("blade-umsUserInfo/umsUserInfo")
@Api(value = "人员基础模型-JAVA", tags = "人员基础模型-JAVA接口")
public class UmsUserInfoController extends BladeController {

	private final IUmsUserInfoService umsUserInfoService;
	private final IMenuService menuService;
	/**
	 * 人员基础模型-JAVA 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入umsUserInfo")
	public R<UmsUserInfoVO> detail(UmsUserInfoEntity umsUserInfo) {
		UmsUserInfoEntity detail = umsUserInfoService.getOne(Condition.getQueryWrapper(umsUserInfo));
		return R.data(UmsUserInfoWrapper.build().entityVO(detail));
	}
	/**
	 * 人员基础模型-JAVA 分页
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入umsUserInfo")
	public R<IPage<UmsUserInfoVO>> list(UmsUserInfoEntity umsUserInfo, Query query) {
		IPage<UmsUserInfoEntity> pages = umsUserInfoService.page(Condition.getPage(query), Condition.getQueryWrapper(umsUserInfo));
		return R.data(UmsUserInfoWrapper.build().pageVO(pages));
	}

	/**
	 * 人员基础模型-JAVA 自定义分页
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入umsUserInfo")
	public R<IPage<UmsUserInfoVO>> page(UmsUserInfoVO umsUserInfo, Query query) {
		IPage<UmsUserInfoVO> pages = umsUserInfoService.selectUmsUserInfoPage(Condition.getPage(query), umsUserInfo);
		return R.data(pages);
	}

	/**
	 * 人员基础模型-JAVA 新增
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入umsUserInfo")
	public R save(@Valid @RequestBody UmsUserInfoEntity umsUserInfo) {
		return R.status(umsUserInfoService.save(umsUserInfo));
	}

	/**
	 * 人员基础模型-JAVA 修改
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入umsUserInfo")
	public R update(@Valid @RequestBody UmsUserInfoEntity umsUserInfo) {
		return R.status(umsUserInfoService.updateById(umsUserInfo));
	}

	/**
	 * 人员基础模型-JAVA 新增或修改
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入umsUserInfo")
	public R submit(@Valid @RequestBody UmsUserInfoEntity umsUserInfo) {
		return R.status(umsUserInfoService.saveOrUpdate(umsUserInfo));
	}

	/**
	 * 人员基础模型-JAVA 删除
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 7)
	@ApiOperation(value = "逻辑删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(umsUserInfoService.deleteLogic(Func.toLongList(ids)));
	}

	@GetMapping("/routes")
	@ApiOperationSupport(order = 8)
	@ApiOperation(value = "前端菜单数据", notes = "前端菜单数据")
	public R<List<MenuVO>> routes(BladeUser user, Long topMenuId) {
		List<MenuVO> list = menuService.routes((user == null) ? null : user.getRoleId(), topMenuId);
		return R.data(list);
	}
	/**
	 * 获取指定路径下的图片
	 *
	 * @param request 响应请求
	 * @param type 类型hd ,org
	 * @param id 目录ID
	 * @return 图片资源
	 * @throws IOException 文件读取异常
	 */
	@GetMapping(value = "/down/{type}/{id}")
	public ResponseEntity<Resource> down(HttpServletRequest request, @PathVariable String type, @PathVariable Long id) throws IOException {
		ResponseEntity<Resource> result=	umsUserInfoService.downData(request,type,id);
		return result;
	}


}
